package com.aoxon.cargo.shared;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.aoxon.cargo.util.DataUtil;
import com.google.gson.Gson;

/**
 * 本地数据保存
 * 
 * @author ZZJ
 * 
 */
public abstract class MyShared {
	private static final String TAG = "MyShared";

	protected static SharedPreferences sp = null;
	protected static Editor editor = null;
	protected static Gson gson = DataUtil.gson;

	public static final void setSharedPreferences(Application application) {
		MyShared.sp = application.getSharedPreferences("MyShared",
				Context.MODE_PRIVATE);
	}

	/**
	 * 保存数据的操作
	 * 
	 * @param where
	 * @param strData
	 */
	public static final void saveDate(String where, String strData) {
		
		editor = sp.edit();
		Log.i(TAG, "save the " + where + " to local : " + strData);
		editor.putString(where, strData);
		editor.commit();
	}
	
	/**
	 * 清空存储的数据
	 */
	public static void clear() {
		editor = sp.edit();
		editor.clear();
		editor.commit();
	}

}
